package com.zjhcsoft.shop.sys.buffer;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.zjhcsoft.shop.dao.SerialDao;
import com.zjhcsoft.shop.dao.TypeDao;
import com.zjhcsoft.shop.model.Serial;
import com.zjhcsoft.shop.model.Type;
import com.zjhcsoft.util.SpringContextHelper;


/**
 * date		  2012-4-9
 * Company    hongcheng
 * @author    dingwanli
 * @version    1.0
 *
 */
public class TypeBuffer {
	
	//原始数据
	public static List<Serial> CLOTHES_SERIAL_LIST_FROMDB = new ArrayList<Serial>();
	public static List<Type> CLOTHES_TYPE_LIST_FROMDB = new ArrayList<Type>();
	
	//类型分类map,主键是typeid
	public static Map<Long,List<Serial>> CLOTHES_SERIAL_FOR_TYPE = new HashMap<Long,List<Serial>>();
	
	//初始化
	public static void init(){
		TypeDao typeDao = (TypeDao)SpringContextHelper.getBean("typeDaoImpl");
		CLOTHES_TYPE_LIST_FROMDB=typeDao.findAll(Type.class);
		
		SerialDao serialDao = (SerialDao)SpringContextHelper.getBean("serialDaoImpl");
		CLOTHES_SERIAL_LIST_FROMDB=serialDao.findAll(Serial.class);

		for (Serial serial : CLOTHES_SERIAL_LIST_FROMDB) {
			List<Serial> l = CLOTHES_SERIAL_FOR_TYPE.get(serial.getParentid());
			if(l==null){
				l = new ArrayList<Serial>();
				l.add(serial);
				CLOTHES_SERIAL_FOR_TYPE.put(serial.getParentid(),l);
			}else{
				l.add(serial);
			}
		}
	}
	
	//方法
	public static List<Serial> getSerialByTypeId(Long id){
		return CLOTHES_SERIAL_FOR_TYPE.get(id);
		
	}

}
